# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=tootik
pkgver=0.12.6
pkgrel=0
pkgdesc="Federated nanoblogging service with Gemini frontend"
url="https://github.com/dimkr/tootik"
arch="all"
license="Apache-2.0"
depends_openrc="openssl"
makedepends="go sqlite-dev"
install="$pkgname.pre-install"
pkgusers="tootik"
pkggroups="tootik"
subpackages="$pkgname-openrc"
source="https://github.com/dimkr/tootik/archive/refs/tags/$pkgver/tootik-$pkgver.tar.gz
	tootik.cfg
	tootik.initd
	tootik.confd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

export CGO_ENABLED=1
export _GOTAGS="libsqlite3 fts5"

build() {
	local _goldflags="
		-X github.com/dimkr/tootik/buildinfo.Version=$pkgver
		"

	go generate -v ./migrations
	go vet -v -tags "$_GOTAGS" ./...
	go build -v -ldflags "$_goldflags" -tags "$_GOTAGS" ./cmd/tootik
}

check() {
	./tootik --version

	# cleanup sqlite database files used by test/register_test.go
	rm -vf /tmp/TestRegister*.sqlite3

	go test -v -tags "$_GOTAGS" -timeout 30m ./...
}

package() {
	install -Dm755 tootik -t "$pkgdir"/usr/bin/
	install -dm750 -o tootik -g tootik "$pkgdir"/var/lib/tootik

	install -dm750 -o tootik -g tootik "$pkgdir"/etc/tootik
	install -Dm640 -o tootik -g tootik "$srcdir"/tootik.cfg \
		-t "$pkgdir"/etc/tootik/

	install -Dm755 "$srcdir"/tootik.initd "$pkgdir"/etc/init.d/tootik
	install -Dm644 "$srcdir"/tootik.confd "$pkgdir"/etc/conf.d/tootik
}

sha512sums="
98a013ae46770a73f8baf9ace264bdf1c2740d42014d69a0efd4067dcfc0cab2c7ac877a3af786757fee4d2905ab758f311b6373cd60488aedac29e4ce3d3280  tootik-0.12.6.tar.gz
c1920846860628f8cfb88d1b9b721acd80a29e7939e93661350c1aa8bd3826d7f891d7e837b566c75ed74fc3b0a91203c083fcb22d78eac0ff718c069c8f9455  tootik.cfg
27e2900591d93829dbde0775cffe8a6098cabb0f4366ebd059902da991229686145650a842adb2c28ccae7f9180bd80c8fd054af9e58799eeb4844a3b53ff503  tootik.initd
11fa51d25baaeb295c80cf3e154eb1eab67f9633e23f01cc0a25c427af368746d536bff17de2153b5be925489e3f84ca5ba492a4a43c32aaf33b8c4d00d14fd6  tootik.confd
"
